<?php
function echoPlayerdeadsRow($team, $dead, $row) {
    echo getEchoTR(($row +1), "center");
    echo "  <td align=left>" . getEchoValue($team->getRosterLink()) . "</td>\n";
    echo "  <td align=left>" . getEchoValue($dead->link) . getEchoValue($dead->name) ." </a></td>\n";
    echo "  <td align=left>" . getEchoValue($dead->position) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->ma) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->st) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->ag) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->av) . "</td>\n";
    echo "  <td align=left><font size=\"-1\">" . getEchoValue($dead->skills) . "</font></td>\n";
    echo "  <td>" . getEchoValue($dead->completions) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->tds) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->interceptions) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->casualties) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->mvps) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->exps) . "</td>\n";
    echo "  <td>" . getEchoValue($dead->spps) . "</td>\n";
    echo "</tr>\n";
}

function echoPlayerDeadsHeader($sort, $teamId = "") {
	
echo<<< EOQ
            <tr align="center">
EOQ;
	echo getLink("Team", $teamId, 9, $sort);            
	echo getLink("Name", $teamId, 10, $sort);            
	echo getLink("Position", $teamId, 12, $sort);            
	echo getLink("ma", $teamId, 13, $sort);            
	echo getLink("st", $teamId, 14, $sort);            
	echo getLink("ag", $teamId, 15, $sort);            
	echo getLink("av", $teamId, 16, $sort);            
	echo getLink("Skills", $teamId, 17, $sort);            
	echo getLink("cp", $teamId, 3, $sort);            
	echo getLink("td", $teamId, 4, $sort);            
	echo getLink("in", $teamId, 5, $sort);            
	echo getLink("cs", $teamId, 6, $sort);            
	echo getLink("mvps", $teamId, 7, $sort);            
	echo getLink("exps", $teamId, 8, $sort);            
	echo getLink("spps", $teamId, 2, $sort);            
echo<<< EOQ
            </tr>
EOQ;
}

function getLink($name, $teamId, $thisSort, $pastSort) {
    if ($thisSort == $pastSort) {
        return "<th><a href=\"?sort=$thisSort&dir=ASC&id=$teamId\">$name</a>";
    } else {
        return "<th><a href=\"?sort=$thisSort&dir=DESC&id=$teamId\">$name</a>";
    }
}
    
function loadPlayerDeads($sort, $direction = "desc") {
    $deads = array ();
    $rs = executeQuery("select completions + (3 * touchdowns) + (2 * interceptions) + (2 * casualties) as spps, " .
    		"completions + (3 * touchdowns) + (2 * interceptions) + (2 * casualties) + (5* mvps) + exps as totalSpps, " .
    		"completions, touchdowns, interceptions, casualties, mvps, exps, fk_team_id, name, roster_num, position, " .
    		"ma, st, ag, av, skills, player_id, comments from players " .
    		"where dead =1 and position not like 'Journeyman' order by $sort $direction, 2 desc limit 0, 25");
    while ($row = mysql_fetch_row($rs)) {
        array_push($deads, new PlayerDead($row));
    }
    return $deads;
}

function loadTeamPlayerDeads($teamId, $sort, $direction = "desc") {
    $deads = array ();
    $rs = executeQuery("select completions + (3 * touchdowns) + (2 * interceptions) + (2 * casualties) as spps, " .
    		"completions + (3 * touchdowns) + (2 * interceptions) + (2 * casualties) + (5* mvps) + exps as totalSpps, " .
    		"completions, touchdowns, interceptions, casualties, mvps, exps, fk_team_id, name, roster_num, position, " .
    		"ma, st, ag, av, skills, player_id, comments from players " .
    		"where dead =1 and position not like 'Journeyman' and fk_team_id=$teamId " .
    		"order by player_id asc");
    while ($row = mysql_fetch_row($rs)) {
        array_push($deads, new PlayerDead($row));
    }
    return $deads;
}

class PlayerDead {
    var $teamId;
    var $name;
    var $rosterNum;
    var $position;
    var $ma;
    var $st;
    var $ag;
    var $av;
    var $skills;
    var $completions = 0;
    var $tds = 0;
    var $interceptions = 0;
    var $casualties = 0;
    var $mvps = 0;
    var $exps = 0;
    var $spps = 0;
    var $otherSpps = 0;
    var $playerId;
    var $link = 0;

    function PlayerDead($row) {
        $i = 0;
        $this->otherSpps = $row[$i++];
        $this->spps = $row[$i++];
        $this->completions = $row[$i++];
        $this->tds = $row[$i++];
        $this->interceptions = $row[$i++];
        $this->casualties = $row[$i++];
        $this->mvps = $row[$i++];
        $this->exps = $row[$i++];
        $this->teamId = $row[$i++];
        $this->name = $row[$i++];
        $this->rosterNum = $row[$i++];
        $this->position = $row[$i++];
        $this->ma = $row[$i++];
        $this->st = $row[$i++];
        $this->ag = $row[$i++];
        $this->av = $row[$i++];
        $this->skills = $row[$i++];
        $this->playerId = $row[$i++];
        $this->comments = $row[$i++];
		$this->link="<a href=\"player_details.php?playerId=$this->playerId\" title=\"$this->name Details $this->comments\" class=\"playerName\">";
    }
}
?>